package Zoo.view.zoomanview;

import Zoo.entity.AnimalEntity;
import Zoo.handler.AddAnimalViewHandler;

import javax.swing.*;
import java.awt.*;

/**
 * 动物饲养员增加动物界面
 */
public class AddAnimalView extends JDialog {
    JPanel jPanel = new JPanel();

    JLabel nameLable = new JLabel("动物名称");
    JTextField nameTxt = new JTextField();
    JLabel kindLable = new JLabel("种类");
    JTextField kindTxt = new JTextField();
    JLabel introductionLable = new JLabel("介绍");
    JTextField introductionTxt = new JTextField();
    JLabel ageLable = new JLabel("年龄");
    JTextField ageTxt = new JTextField();
    JLabel healthLable = new JLabel("健康状况");
    JTextField healthTxt = new JTextField();
    JLabel zooparkIDLable = new JLabel("园区id");
    JTextField zooparkIDTxt = new JTextField();

    JButton addBtn = new JButton("添加");

    AddAnimalViewHandler addAnimalViewHandler;

    public AddAnimalView(ZoomenView1 zoomenView1) {
        super(zoomenView1, "添加动物信息", true);

        addAnimalViewHandler = new AddAnimalViewHandler(this, zoomenView1);
        nameLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(nameLable);
        nameTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(nameTxt);

        kindLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(kindLable);
        kindTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(kindTxt);

        introductionLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(introductionLable);
        introductionTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(introductionTxt);

        ageLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(ageLable);
        ageTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(ageTxt);

        healthLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(healthLable);
        healthTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(healthTxt);

        zooparkIDLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(zooparkIDLable);
        zooparkIDTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(zooparkIDTxt);

        Container contentPane = getContentPane();
        contentPane.add(jPanel);
        //监听
        addBtn.addActionListener(addAnimalViewHandler);
        jPanel.add(addBtn);

        setSize(350, 500);
        setLocationRelativeTo(null);
        //DISPOSE_ON_CLOSE：只销毁当前的窗体
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);


    }

    public AnimalEntity buildAnimalEntity() {
        AnimalEntity animalEntity = new AnimalEntity();

        animalEntity.setKind(kindTxt.getText());
        animalEntity.setIntroduction(introductionTxt.getText());
        animalEntity.setName(nameTxt.getText());
        animalEntity.setAge(ageTxt.getText());
        animalEntity.setHealth(healthTxt.getText());
        animalEntity.setParkId(zooparkIDTxt.getText());


        return animalEntity;
    }
}
